<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Product extends CI_Controller {

    /**
     *   网站后台
     *   王超伟
     * 	 2012.09.25
     * 	 art2006art#gmail.com
     */
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->helper('form');
        $this->load->helper('func');
        $this->load->database();
        $this->load->model('menu_process');
        $this->load->model('alblum_process');
        $this->load->model('photos_process');
    }

    public function index() {
        $album_id = get_segment_fuc(4);
        $class_name = __CLASS__;
        $date["menu_single_array"] = get_menu_array(strtolower($class_name));
        $data["menu_array"] = $this->menu_process->menu_front_list(); //菜单排序       
        $data["album_array"] = $this->alblum_process->album_type_array(1); //获取照片封面
         
        if (!isset($album_id)) {
      if (isset($data["album_array"][0]["id"])) {
          $data["album_id"]=$data["album_array"][0]["id"];
          $data["photo_array"] = $this->photos_process->front_photo_list($data["album_array"][0]["id"]);
            }
            else{
                $data["album_id"]=array();
                $data["photo_array"]=array();
            }
        } else {            
   $data["album_id"]=$album_id;
   $data["photo_array"] = $this->photos_process->front_photo_list($album_id);
        }
       // print_r( $data["photo_array"]);
        $this->load->view('front/header_view', $data);
        $this->load->view('front/product_view', $data);
        $this->load->view('front/footer_view');
    }

    public function videoPlay() {
        $album_id = get_segment_fuc(4);
        
       if (is_numeric($album_id)) {
            if (isset($_GET["id"])) {//&&  is_numeric($_GET["id"])
     $sql = "select * from photos where album_id=\"{$album_id}\"  and id=\"{$_GET["id"]}\" limit 1 "; //获取满足分类的全部数据                            
                $query = $this->db->query($sql);
                $res = $query->result_array();
                if (!empty($res)) {
                     $sql_next = "select * from photos where album_id=\"{$album_id}\"  and id >\"{$_GET["id"]}\"  order by id asc  limit 1 "; //获取满足分类的全部数据            
                    $query = $this->db->query($sql_next);
                    $res_next = $query->result_array();
                    $sql_prev = "select * from photos where album_id=\"{$album_id}\"  and id <\"{$_GET["id"]}\"  order by id desc limit 1 "; //获取满足分类的全部数据                    
                    $query = $this->db->query($sql_prev);
                    $res_prev = $query->result_array();
                    $data["res_next"] = $res_next;
                    $data["res_prev"] = $res_prev;
                } else {
                        redirect('front/product', 'refresh'); 
                    $data["res_next"] = array();
                    $data["res_prev"] = array();
                }
                $data["photo_single"] = $res;
            } else {   //如果设定其他get值  ,默认显示           
                $sql = "select * from photos where album_id=\"{$album_id}\" limit 1 "; //获取满足分类的全部数据  
                $query = $this->db->query($sql);
                $res = $query->result_array();
                $data["photo_single"] = $res;
                if (!empty($res)) {
                     $sql_next = "select * from photos where album_id=\"{$album_id}\"  and id >\"{$res[0]["id"]}\" order by id asc limit 1 "; //获取满足分类的全部数据            
                    $query = $this->db->query($sql_next);
                    $res_next = $query->result_array();
                    $sql_prev = "select * from photos where album_id=\"{$album_id}\"  and id <\"{$res[0]["id"]}\"  order by id desc limit 1 "; //获取满足分类的全部数据                    
                    $query = $this->db->query($sql_prev);
                    $res_prev = $query->result_array();
                    $data["res_next"] = $res_next;
                    $data["res_prev"] = $res_prev;
                } else {
                    redirect('front/product', 'refresh'); 
                    $data["res_next"] = array();
                    $data["res_prev"] = array();
                }
            }
           
        } else {
             redirect('front/product', 'refresh'); 
            //跳转到index.php/front/photo 
        } 
      
        $class_name = __CLASS__;

        $data["menu_array"] = $this->menu_process->menu_front_list(); //菜单排序  


        $data["album_array"] = $this->alblum_process->album_type_array(1); //获取照片封面

        $this->load->view('front/header_view', $data);
        $this->load->view('front/videoPlay_view', $data);
        $this->load->view('front/footer_view');
    }

}

/* End of file admin.php */
/* Location: ./application/controllers/admin.php */